﻿
//let passwordCheckBoxToTextMap = new Map();
//let passwordTextSet = new Set();
let globalPasswordShowHidefunc = {};

(function regGlobalPasswordShowHide() {
    //console.log(globalPasswordShowHidefunc);
    window.removeEventListener("click", globalPasswordShowHidefunc);
    //passwordCheckBoxToTextMap = new Map();
    //passwordTextSet = new Set();

    //let passwordSectionList = document.getElementsByClassName("toggle-password");
    //for (let passwordSection of passwordSectionList) {
    //    let checkboxs = passwordSection.getElementsByClassName("toggle-password-checkbox");
    //    let texts = passwordSection.getElementsByClassName("toggle-password-text");
    //    Array.from(texts).forEach(m => passwordTextSet.add(m));
    //    if (checkboxs.length > 0 && texts.length > 0) {
    //        //console.log(checkboxs[0]);
    //        //console.log(texts[0]);
    //        passwordCheckBoxToTextMap.set(checkboxs[0], texts[0]);
    //    }
    //}


    globalPasswordShowHidefunc = (e) => {
        if (!e.target.classList.contains("toggle-password-checkbox"))
            return;

        let current = e.target;
        let host = null;
        while (current) {
            if (current.classList.contains("toggle-password")) {
                host = current;
                break;
            }
            current = current.parentElement;
        }
        if (host == null)
            throw `'toggle-password' class not found for: ${e.target}`;

        var elems = host.getElementsByClassName("toggle-password-text");
        if (elems.length< 1)
            throw `'toggle-password-text' class not found for: ${host}`;

        //console.log(e);
        let passwordText = elems[0];
        if (passwordText != undefined) {
            //console.log('show');
            //console.log(e.target);
            if (passwordText.type === "password")
                passwordText.type = "text";
            else
                passwordText.type = "password";
        }
    }
    window.addEventListener("click", globalPasswordShowHidefunc);
})()

